<?php
namespace Admin\Controller;
use Think\Controller;

/**
 * Class ExamReadController
 * @package Admin\Controller
 * 阅卷部分
 */
class ExamReadController extends BaseControlle {
    public function __construct()
    {
        parent::__construct();
    }

    public function index(){

    }
    public function Manage(){
        $assignmentid = I('get.assignmentid',0,'intval');
        $this->assign('assignmentid',$assignmentid);
        $this->display();
    }

    public function ReaderUI(){
        $this->display();
    }

    public function ReaderQuery(){
        if(IS_AJAX){
            $assignmentid = I('post.assignmentid',0,'intval');
            $grade        = I('post.grade',0,'intval');
            $class        = I('post.class',0,'intval');
            $page         = I('post.page',0,'intval');
            $limit        = I('post.limit',0,'intval');
            $DB_PREFIX    = C('DB_PREFIX');
            $where = array();
            $ret   = array('code'=> 0, 'msg'=>"", 'count'=> 0, 'data'=>array());
            //检查传入的数据是否正确
            if ($assignmentid == 0){
                $ret['code'] = 500;
                $ret['msg']  = '查询的题号不正确';
                $this->ajaxReturn($ret);
            }

            $where['exam_assignment_id'] = $assignmentid;
            //对数据库查询数据进行过滤
            if ($grade != 0){
                $where['grade'] = $grade;
            }
            if ($class != 0){
                $where['class'] = $class;
            }

            $student_exam_result = M('student_exam_result');
            $ret_student_exam_result_count = $student_exam_result
                ->join('__STUDENT_INFORMATION__ ON __STUDENT_EXAM_RESULT__.student_id=__STUDENT_INFORMATION__.uid','LEFT')
                ->where($where)->count();
            $page   = DBPage($ret_student_exam_result_count,$limit,$page);
            $ret_student_exam_result = $student_exam_result
                ->join('__STUDENT_INFORMATION__ ON __STUDENT_EXAM_RESULT__.student_id=__STUDENT_INFORMATION__.uid','LEFT')
                ->where($where)
                ->limit($limit)
                ->page($page['page'])
                ->order('id ASC,is_examread ASC')
                ->select();
            if ($ret_student_exam_result){
                $ret = array(
                    'code'=> 0,
                    'msg'=>"",
                    'count'=> $ret_student_exam_result_count,
                    'data'=>$ret_student_exam_result
                );
                $this->ajaxReturn($ret);
            }else{
                $ret['code'] = 500;
                $ret['msg']  = '还没有数据哦,或者查询失败';
                $this->ajaxReturn($ret);
            }
        }else{
            if (IS_POST){
                $this->ajaxReturn(array('code'=>500,'msg'=>'接口错误调用'));
            }else{
                $this->error('您无权访问');
            }
        }
    }

}